package com.dmooo.yxmmerchant.view.model;

import android.content.Context;

import com.common.net.entity.SubjectPost;
import com.common.net.listener.HttpOnNextListener;
import com.common.net.subscribers.ProgressSubscriber;
import com.common.util.LogUtil;
import com.dmooo.yxmmerchant.base.SignUtils;
import com.dmooo.yxmmerchant.common.Config;
import com.dmooo.yxmmerchant.http.HttpManager;
import com.dmooo.yxmmerchant.view.contract.PassWordContract;

import java.util.HashMap;
import java.util.Map;

public class PassWordModel implements PassWordContract.PassWordMdl {
    private Context context;
    public PassWordModel(Context context) {
        this.context=context;
    }
    //获取提现密码设置验证码
    @Override
    public void getPhoneCode(String token, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"获取验证码"),map);
        HttpManager.getInstance().sendDrawPwdCode(post);
    }
    //设置提现验证码
    @Override
    public void setDrawPwd(String token, String code, String pwd1, String pwd2, HttpOnNextListener listener) {

        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("code",code);
        map.put("pwd1",pwd1);
        map.put("pwd2",pwd2);
        map=SignUtils.addCommonParams(map,Config.MERCHANT_SET_DRAW_PWD);
        map.put("sign", SignUtils.getSign(map));
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"申请提现中"),map);
        HttpManager.getInstance().setDrawPwd(post);
    }

    /**
     * 用户提现，此接口需要签名验证
     * @param token
     * @param account_type
     * @param account
     * @param money
     * @param truename
     * @param listener
     */

    @Override
    public void userDrawMoney(String token, String account_type, String account, String money, String truename,HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("account_id",account_type);
//        map.put("account",account);
        map.put("money",money);
//        map.put("truename",truename);
//        map=SignUtils.addCommonParams(map,Config.USER_DRAW_TYPE);
//        map.put("sign", SignUtils.getSign(map));
        LogUtil.d("fsadfsd",map.toString());
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"申请提现中"),map);
        HttpManager.getInstance().userDrawMoney(post);
    }

    @Override
    public void isSetDrawPwd(String token, HttpOnNextListener listener) {
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,false,false,"设置中"),map);
        HttpManager.getInstance().isSetDrawPwd(post);
    }

    @Override
    public void checkDrawPwdCorrect(String token, String pwd, HttpOnNextListener listener) {
//        Map<String,Object> map=new HashMap<>();
//        map.put("token",token);
//        map.put("pwd",pwd);
//        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"验证密码"),map);
//        HttpManager.getInstance().checkDrawPwd(post);
        Map<String,Object> map=new HashMap<>();
        map.put("token",token);
        map.put("pwd",pwd);
        map=SignUtils.addCommonParams(map,Config.MERCHANT_IS_DRAW_PWD_CORRECT);
        map.put("sign", SignUtils.getSign(map));
        SubjectPost post=new SubjectPost(new ProgressSubscriber(listener,context,true,false,"申请提现中"),map);
        HttpManager.getInstance().checkDrawPwd(post);
    }
}
